package com.wowangz.cms.systemmanage.country.service;

import java.util.HashMap;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.wowangz.cms.syscore.exception.ServiceException;
import com.wowangz.cms.syscore.service.BaseService;
import com.wowangz.cms.systemmanage.city.pojo.City;
import com.wowangz.cms.systemmanage.country.pojo.Country;

public class CountryService extends BaseService {

	private Logger logger = LoggerFactory.getLogger(CountryService.class);

	/**
	 * 新增省信息
	 * @param province
	 * @throws Exception
	 */
	public void add(Country country) throws ServiceException {
		this.getSqlSession().insert("Country.insertCountry", country);
	}
	/**
	 * 分页查询总条数
	 * 
	 * @param map
	 * @return
	 */
	public long findResultCount(HashMap<String, Object> map) throws ServiceException {
		Long countNum = this.getSqlSession().selectOne("Country.queryCountryCount", map);
		return countNum;
	}

	/**
	 * 查询记录集合
	 * 
	 * @param map
	 * @return
	 */
	public List<City> findResultList(HashMap<String, Object> map) throws ServiceException {
		List<City> list = this.getSqlSession().selectList("Country.queryCountryPage", map);
		return list;
	}
	
	/**
	 * 验证信息
	 * @param map
	 * @return
	 * @throws Exception
	 */
	public boolean validationCity(HashMap<String, Object> map) throws ServiceException {
		Long countNum = this.getSqlSession().selectOne("Country.validationCountry", map);
		if(countNum != 0){
			return false;
		}else{
			return true;
		}
	}
	
	public Country findCountryById(String id) throws ServiceException {
		Country country = this.getSqlSession().selectOne("Country.findCountryById", id);
		return country;
	}
	
	public void update(Country country) throws Exception {
		this.getSqlSession().update("Country.updateCountry", country);
	}
	
	public List<City> findCityByProvinceId(Long id) throws ServiceException {
		List<City> list = this.getSqlSession().selectList("City.findCityByProvinceId", id);
		return list;
	}
	

}
